#include<func.h>
void*pthreaFunc(void*arg)
{
    sleep(5);//让主线程先关掉
    //子线程访问文件对象
    int *fd = (int*)arg;
    int fd2 = *fd;
    lseek(fd2,0,SEEK_SET);//从0开始读
    //printf("fd = %d\n",*fd);
    char buf[4096]={0};
    ERROR_CHECK(fd2,-1,"open");
    ssize_t sret = read(fd2,buf,sizeof(buf));
    printf("buf = %s,sret = %ld\n",buf,sret);

}
int main(int argc,char*argv[])
{
    //主线程打开+close
    //./test2 file1
    ARGS_CHECK(argc,2);
    int fd = open(argv[1],O_RDWR);
    ERROR_CHECK(fd,-1,"open");
    write(fd,"helloworld",11);
    //创建子线程
    pthread_t td;
    pthread_create(&td,NULL,pthreaFunc,&fd);//传入fd数据
    close(fd);
    sleep(10);
    return 0;
}